package com.qf.servelt3;

import javax.servlet.ServletException;
import javax.servlet.SingleThreadModel;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;

public class SafeServlet extends HttpServlet implements SingleThreadModel {
//    private String message = "";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String message = "";
//      synchronized 改变线程多并发问题但是系统欢迎速度慢，所以不支持使用
        synchronized (this) {
            // 1.假设调用接收参数
            // 2. 调用业务逻辑，得到登录结果
            message = "登陆成功"; // 登录失败
            PrintWriter printWriter = resp.getWriter();
            printWriter.println(message);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
